<?php
/**
 * 管理链接页面
 * $Id: manage_links.php 192 2010-11-04 07:52:58Z bwanglei@gmail.com $
 */

require_once './globals.php';
require_once AW_ROOT.'/model/class.link.php';

$aw_link = new awLink();
$blog_title = '添加 & 修改链接 - '.$blogname;
$links = $CACHE->readCache('links');

//添加链接
if ($action=='add-link' && $_SERVER['REQUEST_METHOD']=='POST') {
	$name_link = isset($_POST['link_name']) ? $_POST['link_name'] : '';
	$url_link = isset($_POST['link_url']) ? $_POST['link_url'] : '';
	$aw_link->addLink($name_link, $url_link);
	$CACHE->updateCache('links');
	header('Location: '.$blogUrl.'/admin/manage_links.php'); exit;
}

//更新&删除链接
if ($action=='update-del-link' && $_SERVER['REQUEST_METHOD']=='POST') {
	if (isset($_POST['del']) && $_POST['del']=='del_link') {
		$del_id = $_POST['link_id'];
		$aw_link->deleteLink($del_id);
	} else {
		$id_u = $_POST['link_id'];
		$name_u = $_POST['link_name'];
		$url_u = $_POST['link_url'];
		$aw_link->updateLinks(array('id'=>$id_u,'name'=>$name_u,'url'=>$url_u));
	}
	$CACHE->updateCache('links');	//更新缓存
	$page = (isset($_GET['page']) ? '?page='.$_GET['page'] : '');
	header('Location: '.$blogUrl.'/admin/manage_links.php'.$page);exit;
}
include_once TEMPLATE_PATH.'/header.php';
include_once TEMPLATE_PATH.'/manage_links.php';
include_once TEMPLATE_PATH.'/sidebar.php';
include_once TEMPLATE_PATH.'/footer.php';
